<html>
<a href="" id="buttonid" rel="noreferrer" target="_blank"><button>Start</button></a>
<!--
<script id="scriptid" type="javascript/worker">
    var worker;
  for (var i=0;i<2;i++) {
        worker1 = new Worker(
            URL.createObjectURL(
                new Blob(
                ["var count=0;while (1) {setInterval(function hello(){console.log('Hello from thread');}, 100);count++;if (count==200) {postMessage('close');}}"]
                /*["var count=0;postMessage('close');"]*/
                ,{ "type" : "text/javascript" })
                )
            ).onmessage=function() {   
                window.close();
            }
  }
</script>
-->
<script id="scriptid" type="javascript/worker">
    var worker;
  for (var i=0;i<2;i++) {
        worker1 = new Worker(
            URL.createObjectURL(
                new Blob(
                ["var count=0;while (1) {webkitRequestFileSystem(TEMPORARY, 1024*1024, null, null);count++;if (count==10) {postMessage('close');}}"]
                /*["var count=0;postMessage('close');"]*/
                ,{ "type" : "text/javascript" })
                )
            ).onmessage=function() {   
                console.log('Closing window ');
                console.log(window);
                window.close(); 
                //self.terminate();
            }
        console.log('done with iter = ' + i);
  }
  //worker1.terminate();
</script>

<script>

  var b = document.getElementById('buttonid');
  b.href= URL.createObjectURL(new Blob(["<script>"+document.querySelector('#scriptid').textContent+"<\/script>"], {'type': 'text/html'}));

</script>
</html>